﻿using MediatR;
using Traceability.App.API.Application.Command.HealthInformation;
using Traceability.App.Domain.Traceability;
using Traceability.App.ErrorCode;
using Traceability.App.Infrastructrue.Interface;

namespace Traceability.App.API.Application.Handler.HealthInformation
{
    public class GetHealthHandler : IRequestHandler<GetHealthCommand, APIResult<List<HealthInformationModel>>>
    {
        private readonly IBaseRepository<HealthInformationModel> healthRepo;

        public GetHealthHandler(IBaseRepository<HealthInformationModel> healthRepo)
        {
            this.healthRepo = healthRepo;
        }
        public Task<APIResult<List<HealthInformationModel>>> Handle(GetHealthCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<HealthInformationModel>> result = new APIResult<List<HealthInformationModel>>();
            var res = healthRepo.GetAll().Where(x => !x.IsDel&&x.Batch==request.Batch).ToList();
            result.Message = "显示成功";
            result.Data = res;
            result.Code = APIEnum.Ok;
            return Task.FromResult(result);
        }
    }
}
